package com.atguigu.champter5.Flink05.transformation.base;


import com.atguigu.beans.WaterSensor;
import com.atguigu.source.RandomWaterSenson;
import org.apache.flink.api.common.functions.FlatMapFunction;
import org.apache.flink.streaming.api.environment.StreamExecutionEnvironment;
import org.apache.flink.util.Collector;

import java.util.Iterator;

public class $3_FlatMap {
    public static void main(String[] args) {
        StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment();
        /*env.fromElements(1,2,3,4)
                .flatMap(new FlatMapFunction<Integer, Double>() {
                    @Override
                    public void flatMap(Integer value, Collector<Double> out) throws Exception {
                        out.collect(value.doubleValue());

                    }
                }).print();*/
        env.addSource(new RandomWaterSenson())
                .flatMap(new FlatMapFunction<WaterSensor, WaterSensor>() {
                    @Override
                    public void flatMap(WaterSensor value, Collector<WaterSensor> out) throws Exception {
                        if (value.getVc() > 50){
                            out.collect(value);
                        }

                    }
                }).print();
        try {
            env.execute();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
